package com.dgut.app.config;

import cn.binarywang.wx.miniapp.api.WxMaMsgService;
import cn.binarywang.wx.miniapp.bean.WxMaSubscribeMessage;
import com.dgut.app.service.OrderService;
import com.dgut.common.config.WxAppConfig;
import com.dgut.common.mapper.CollectionOrderMapper;
import com.dgut.common.mapper.WxUserMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import java.util.ArrayList;
import java.util.List;

/**
 * @author IT00ZYQ
 * @date 2022/1/5 18:15
 **/
@Configuration
@EnableScheduling
@Slf4j
@RequiredArgsConstructor
public class TimeTask {

    private final CollectionOrderMapper orderMapper;

    @Scheduled(fixedRate = 10 * 60 * 1000)
    public void timeout() {
        log.info("[更新订单状态定时任务执行] 订单超时数: {}", orderMapper.timeout());
    }

//    /**
//     * 订阅消息
//     * @param openid 微信用户openid
//     */
//    private void messageTemplate(String openid) {
//        WxMaSubscribeMessage.Data thing1 = new WxMaSubscribeMessage.Data("thing1", TITLE);
//        WxMaSubscribeMessage.Data thing2 = new WxMaSubscribeMessage.Data("thing2", CONTENT);
//        List<WxMaSubscribeMessage.Data> list = new ArrayList<>();
//        list.add(thing1);
//        list.add(thing2);
//        WxMaSubscribeMessage msg = WxMaSubscribeMessage.builder().toUser(openid).templateId(TEMPLATE_ID)
//                .page("pages/index/index").data(list).build();
//        WxMaMsgService msgService = WxAppConfig.wxMaService.getMsgService();
//        try {
//            msgService.sendSubscribeMsg(msg);
//        } catch (WxErrorException e) {
//            log.error("发送提醒每日日记与记账订阅消息失败，原因:{}",e.getMessage());
//        }
//    }

}
